package gsp420.game;

import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JApplet;
import javax.swing.JFrame;

/**
 * to make into an Applet:
 * right-mouse click on the project
 * [Export]->[Java]->[JAR File]
 * select the resources required to export
 * select a destination with [Browse] (like ...Desktop\export.jar
 * [Next]
 * [Next]
 * select a Main class (one with public static void main() in it)
 * [Finish]
 * 
 * in the directory with the .jar file, make the following html file:<br><br>
 * <code>
 * &lt;applet archive="export.jar" CODE="com.package.main.class" width=90% height=90%&gt;<br>
 * &lt;param name="someParam" value="someValue"/&gt;<br>
 * &lt;/applet&gt;
 * </code>
 */
public class Application extends JApplet {
	/** not intended for serialization */
	private static final long serialVersionUID = 1L;

	/**
	 * starts up the game in a new JFrame.
	 * I want to explain how this works in my brain.
	 * My rhymes, they are lame, but my code brings me fame.
	 * Progrizzle in my hizzle.
	 * @param args
	 */
	public static void main(String[] args)
	{
		JFrame jf = new JFrame("labyrinth");
		Toolkit t = Toolkit.getDefaultToolkit();
		Image[] playerImages = {
				t.createImage("icon1.png"),
				t.createImage("icon0.png"),
				t.createImage("icon2.png"),
				t.createImage("icon3.png"),
		};
		Image[] goalImages = {
				t.createImage("goal0.png"),
				t.createImage("goal1.png"),
				t.createImage("goal2.png"),
				t.createImage("goal3.png"),
				t.createImage("goal4.png"),
				t.createImage("goal5.png"),
				t.createImage("goal6.png"),
				t.createImage("goal7.png"),
				t.createImage("goal8.png"),
				t.createImage("goal9.png"),
				t.createImage("goal10.png"),
				t.createImage("goal11.png"),
		};
		GamePanel gp = new GamePanel(playerImages, goalImages);
		jf.add(gp);
		jf.setSize(500,500);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		gp.requestFocus();
	}
	
	public void init()
	{
		Image[] playerImages = null, goalImages;
		try{
			playerImages = new Image[]{
				getImage(getCodeBase(), "./icon1.png"),
				getImage(getCodeBase(), "./icon0.png"),
				getImage(getCodeBase(), "./icon2.png"),
				getImage(getCodeBase(), "./icon3.png"),
			};
			goalImages = new Image[]{
				getImage(getCodeBase(), "./goal0.png"),
				getImage(getCodeBase(), "./goal1.png"),
				getImage(getCodeBase(), "./goal2.png"),
				getImage(getCodeBase(), "./goal3.png"),
				getImage(getCodeBase(), "./goal4.png"),
				getImage(getCodeBase(), "./goal5.png"),
				getImage(getCodeBase(), "./goal6.png"),
				getImage(getCodeBase(), "./goal7.png"),
				getImage(getCodeBase(), "./goal8.png"),
				getImage(getCodeBase(), "./goal9.png"),
				getImage(getCodeBase(), "./goal10.png"),
				getImage(getCodeBase(), "./goal11.png"),
			};
		}catch(Exception e){
			e.printStackTrace();
			playerImages = new Image[4];
			goalImages = new Image[12];
		}
		// grabs a string argument passed into the applet via the <param> tag
		String someParam = getParameter("someParam");
		System.out.println(someParam);
		GamePanel gp = new GamePanel(playerImages, goalImages);
		add(gp);
		gp.requestFocus();
	}
}
